package com.link2room.rodimus.controller.api;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.rodimus.dto.param.api.DoDrawParamDto;
import com.link2room.rodimus.dto.param.api.DrawDeliverInfoParamDto;
import com.link2room.rodimus.dto.param.api.DrawLogsParamDto;
import com.link2room.rodimus.facade.IDrawFacadeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 抽奖
 * Created by LN on 2017/7/11.16:08
 */
@Api(tags = "抽奖相关")
@RestController
@RequestMapping("/api/Draw")
public class DrawApiController {
    @Resource
    private IDrawFacadeService drawFacadeService;

    @RequestMapping(value = "/doDraw", method = RequestMethod.POST)
    public BaseResultDto doDraw(@RequestParam(name = "drawCode",required = false) String drawCode, @RequestParam(name = "activityCode") String activityCode) throws Exception {
        DoDrawParamDto paramDto = new DoDrawParamDto();
        paramDto.setDrawCode(drawCode);
        paramDto.setActivityCode(activityCode);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(drawFacadeService.doDrawResultNew(paramDto));
        return resDto;
    }
    
    @RequestMapping(value = "/drawChanceCount",method = RequestMethod.GET)
    public BaseResultDto drawChanceCount(

            @RequestParam(name = "activityCode", required = false) String activityCode
    ) throws Exception {
        DoDrawParamDto paramDto = new DoDrawParamDto();
        paramDto.setActivityCode(activityCode);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(drawFacadeService.findDrawChanceCount(paramDto));
        return resDto;
    }

    @RequestMapping(value = "/userDrawLogs", method = RequestMethod.GET)
    public BaseResultDto userDrawLogs() throws Exception {
        BaseL2rParamDto paramDto = new BaseL2rParamDto();

        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setListToQueryResult(drawFacadeService.userDrawLogList(paramDto));
        return resDto;
    }


    @RequestMapping(value = "/logs", method = RequestMethod.GET)
    public BaseResultDto logs(
            @RequestParam(name = "type", required = false) String type,
            @RequestParam(name = "isWon", required = false) String isWon,
            @RequestParam(name = "prizeCode", required = false) String prizeCode,
            @RequestParam(name = "activityCode", required = false) String activityCode
    ) throws Exception {
        DrawLogsParamDto paramDto = new DrawLogsParamDto();
        paramDto.setIsWon(isWon);
        paramDto.setActivityCode(activityCode);
        paramDto.setPrizeCode(prizeCode);
        paramDto.setType(type);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setListToQueryResult(drawFacadeService.logs(paramDto));
        return resDto;
    }

    @RequestMapping(value = "/deliverInfo", method = RequestMethod.POST)
    public BaseResultDto deliverInfo(
            @RequestBody DrawDeliverInfoParamDto paramDto
    ) throws Exception {
        drawFacadeService.addDeliverInfo(paramDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }

    @RequestMapping(value = "/deliverInfo", method = RequestMethod.GET)
    public BaseResultDto getDeliverInfo(@RequestParam(name = "prizeNo") String prizeNo) throws Exception {
        DrawDeliverInfoParamDto param = new DrawDeliverInfoParamDto();
        param.setPrizeNo(prizeNo);

        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultInfo(drawFacadeService.getDeliverInfoByPrizeNo(param));
        resDto.setResultCode(0);
        return resDto;
    }
    
    @RequestMapping(value = "/doDrawWithPrizeCode", method = RequestMethod.POST)
    public BaseResultDto doDrawByLevel(@RequestParam(name = "prizeCode") String prizeCode, @RequestParam(name = "activityCode") String activityCode) throws Exception {
        DoDrawParamDto paramDto = new DoDrawParamDto();
        paramDto.setActivityCode(activityCode);
        paramDto.setPrizeCode(prizeCode);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(drawFacadeService.doDrawResultWithPrizeCode(paramDto));
        return resDto;
    }
    
    @RequestMapping(value = "/drawChanceInitCount",method = RequestMethod.GET)
    public BaseResultDto drawChanceInitCount(@RequestParam(name = "activityCode", required = false) String activityCode
    ) throws Exception {
        DoDrawParamDto paramDto = new DoDrawParamDto();
        paramDto.setActivityCode(activityCode);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(drawFacadeService.initDrawChanceCount(paramDto));
        return resDto;
    }

}
